<template>
    <div>
        <div class="searchForm">
            <div class="column">
                <span>目录名：</span>
                <el-input style="height: 21px;width: 136px" placeholder="请输入目录名" v-model="searchForm.name"/>
            </div>
            <div class="column">
                <el-button type="success" @click="submitSearchForm">搜索</el-button>
                <el-button type="info" @click="resetSearchForm">重置</el-button>
            </div>
        </div>
        <div class="table">
            <el-table
                    :data="tableData"
                    style="width: 100%;"
                    height="450px"
                    size="medium"
                    row-key="id"
                    border
                    :tree-props="{children: 'children'}">
                <el-table-column
                        prop="label"
                        label="菜单名">
                </el-table-column>
                <el-table-column
                        prop="flag"
                        :show-overflow-tooltip="true"
                        label="标识符">
                    <template v-slot="scope">
                        <el-tag type="info">{{scope.row.flag?scope.row.flag:'暂定'}}</el-tag>
                    </template>
                </el-table-column>
                <el-table-column
                        prop="type"
                        label="类型">
                    <template v-slot="scope">
                        <el-tag effect="dark" v-if="scope.row.type==0">目录</el-tag>
                        <el-tag effect="dark" v-else-if="scope.row.type==1" type="success">菜单</el-tag>
                        <el-tag effect="dark" v-else type="warning">按钮</el-tag>
                    </template>
                </el-table-column>
                <el-table-column
                        prop="icon"
                        label="图标">
                    <template v-slot="scope">
                        <i :class="scope.row.icon"></i>
                    </template>

                </el-table-column>
                <el-table-column
                        prop="info"
                        :show-overflow-tooltip="true"
                        label="描述">
                    <template v-slot="scope">
                        <el-tag type="info">{{scope.row.info?scope.row.info:'无'}}</el-tag>
                    </template>
                </el-table-column>
                <el-table-column
                        prop="component"
                        :show-overflow-tooltip="true"
                        label="组件路径">
                    <template v-slot="scope">
                        <el-tag type="info">{{scope.row.component?scope.row.component:'暂定'}}</el-tag>
                    </template>
                </el-table-column>
                <el-table-column
                        prop="state"
                        label="状态">
                    <template v-slot="scope">
                        <el-tag effect="dark" type="success" v-if="scope.row.state==0">正常</el-tag>
                        <el-tag effect="dark" type="danger" v-else>禁用</el-tag>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pageUtils">
                <el-pagination
                        @size-change="handleSizeChange"
                        @current-change="handleCurrentChange"
                        :current-page.sync="searchForm.currentPage"
                        :page-sizes="[3, 5, 7, 9]"
                        :page-size="searchForm.pageSize"
                        layout="total,sizes, prev, pager, next,jumper"
                        :total="searchForm.total">
                </el-pagination>
            </div>
        </div>

    </div>
</template>
<script>
    import {queryPageByQo} from "@/api/system/menu/menuApi";
    import {popup} from "@/assets/js/common";

    export default {
        data() {
            return {
                /*搜索*/
                /*表格*/
                tableData: [],
                searchForm:{
                    total:0,
                    currentPage:1,
                    pageSize:3,
                }

            }
        },
        methods: {
            init(){
                queryPageByQo(this.searchForm).then(res=>{
                    res=res.data
                    if (res.code == 200) {
                        console.log(res.data)
                        this.tableData = res.data.records
                        this.searchForm.total=res.data.total
                        this.searchForm.pageSize=res.data.size
                        this.searchForm.currentPage=res.data.current
                    }else {
                        popup(res.msg,"error")
                    }
                })
            },
            submitSearchForm(){
                this.init()
            },
            resetSearchForm(){
                this.searchForm.name=''
            },
            /*分页*/
            handleSizeChange(val) {
                this.searchForm.pageSize=val
                this.init()
                console.log(`每页 ${val} 条`);
            },
            handleCurrentChange(val) {
                this.searchForm.currentPage=val
                this.init()
                console.log(`当前页: ${val}`);
            }
        },
        mounted() {
            this.init()
        }
    }
</script>
<style>
    .searchForm {
        height: 134px;
    }

    .table {
        background-color: #303133;
        height: 320px;
    }

    .pageUtils {
        position: absolute;
        width: 84%;
        margin: 2px auto;
        height: 43px;
    }
    .searchForm {
        display: inline-block;
        margin: 0 auto;
        height: 51px;
        line-height: 51px;
    }

    .searchForm .column {
        display: inline-block;
        margin: 0 auto;
        margin-right: 2px;
        line-height: 48px;
        height: 51px;
    }
</style>